package test12;

import java.io.*;
import java.security.PublicKey;
import java.util.Date;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Student zhangsan = new Student();
        zhangsan.setName("张三");
        zhangsan.setHeight(1.77);
        File file = new File("people.txt");
        try {
            FileOutputStream fileOut = new FileOutputStream(file);
            ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);
            objectOut.writeObject(zhangsan);
            objectOut.close();

            FileInputStream fileIn = new FileInputStream(file);
            ObjectInputStream objectIn = new ObjectInputStream(fileIn);
            Student li = (Student) objectIn.readObject();
            objectIn.close();

            System.out.println(zhangsan.name + "身高是：" + zhangsan.height);
            System.out.println(li.name + "身高是：" + li.height);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            System.out.println("不能读出对象");
        }
    }
}


class Student implements Serializable {
    String name = null;
    double height;

    public void setName(String name) {
        this.name = name;
    }

    public void setHeight(double height) {
        this.height = height;
    }
}